package com.owen.springboot.smartparkingms.module.sys.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.owen.springboot.smartparkingms.common.constant.SystemConstant;
import com.owen.springboot.smartparkingms.common.model.Result;
import com.owen.springboot.smartparkingms.common.util.DateUtils;
import com.owen.springboot.smartparkingms.common.util.ShiroUtils;
import com.owen.springboot.smartparkingms.module.sys.entity.Interface;
import com.owen.springboot.smartparkingms.module.sys.service.IInterfaceService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.unit.DataUnit;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Owen
 * @since 2022-02-28
 */
@RestController
@RequestMapping("/sys/interface")
public class InterfaceController {

    @Autowired
    private IInterfaceService interfaceService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public Result list(Interface interf){
        return interfaceService.listPage(interf);
    }

    /**
     * 获取
     */
    @PostMapping("/get")
    public Result get(Long id){
        Interface interf = interfaceService.getById(id);
        return Result.ok(interf);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresRoles("admin")
    public Result save(@RequestBody Interface interf){
        if (interf.getId() == null) {
            interf.setGmtCreate(DateUtils.getTimestamp());
            interf.setUserIdCreate(ShiroUtils.getUserId());
        }else {
            interf.setGmtModified(DateUtils.getTimestamp());
        }
        interfaceService.saveOrUpdate(interf);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresRoles("admin")
    public Result delete(Long id){
        interfaceService.removeById(id);
        return Result.ok();
    }

    /**
     * 查询
     */
    @PostMapping("/query")
    @RequiresRoles("admin")
    public Result query(Interface entity){
        return interfaceService.selectquery(entity);
    }
}
